<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>loadTable.html</title>
		<script type="text/javascript">
			var xmlreq=false;
			function loadTable(){
				//创建XMLHttpRequest对象
				if(window.XMLHttpRequest){
					xmlreq=new XMLHttpRequest();
				}else{
					try{
						xmlreq=new ActiveXObject("Msxml2.XMLHTTP");
					}catch(e){
						xmlreq=new ActiveXObject("Microsoft.XMLHTTP");
					}
				}
				//发送请求
				xmlreq.open("get","LoadTable?time="+new Date().getTime());
				xmlreq.onreadystatechange=execute;
				xmlreq.send(null);
			}
			//接收响应的xml信息，生成table列表
			function execute(){
				if(xmlreq.readyState==4){
					if(xmlreq.status==200){
						var xmlDoc=xmlreq.responseXML;
						var user=xmlDoc.getElementsByTagName("user");
						clearTable();//清空表格中的tr
						//遍历servlet返回的数据，循环生成tr
						for(var i=0;i<user.length;i++){
							var id = user[i].getElementsByTagName("id")[0].firstChild.data;
							var username=user[i].getElementsByTagName("username")[0].firstChild.data;
							var tb=document.getElementById("tb");
							var tr=tb.insertRow(tb.rows.length)	;
							var id_td=tr.insertCell(tr.cells.length);
							id_td.innerHTML=id;
							var username_td=tr.insertCell(tr.cells.length);
							username_td.innerHTML=username;
						}
					}
				}
			}
			function clearTable(){
				var tb=document.getElementById("tb");
				for(i=tb.rows.length-1;i>=0;i--){
					tb.deleteRow(i);
				}
			}
		</script>
	</head>
	<body>
		<input type="button" value="load" onclick="loadTable()"/>
		<hr/>
		<table id="tb"></table>
	</body>
</html>
